<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class TaskOperate extends AdminController
{
    public $_validation = null;

    function __construct()
    {
        parent::__construct();
    }

    public function index()
    {
        $this->load->library('FormFilter');
        $this->load->helper('formfilter');
        $this->load->model('MAdminGroup');
        $allReviews = $this->MAdminGroup->getReviews();
        ksort($allReviews);
        $this->assign('allReviews', $allReviews);
        $this->layout('taskoperate');
    }

    public function ajaxLineData()
    {
        $this->load->model('MAdminGroup');
        $this->load->model('MTaskRecords');
        $this->load->library('FormFilter');
        $this->load->helper('formfilter');
        $data = $this->input->post();

        $begintime = filterValue('task_operate_create_time_begin');
        $endtime = filterValue('task_operate_create_time_end');

        //销售组与测评组
        $allReviews = $this->MAdminGroup->getChooseReviews($this->input->post('group_id'));
        $list = $this->MTaskRecords->getCountNum($begintime, $endtime, (int)$data['x_value'], $allReviews, $data['type']);

        $child_arr = ['type' => 'line','smooth' => true,'seriesLayoutBy' => 'row'];
        $line = array();
        foreach ($allReviews as $v){
            $line[] = $child_arr;
        }
        $last = ['type' => 'pie','id' => 'pie','radius' => '30%','center' => ['50%', '25%'],'label' => ['formatter' => '{b}: {@2019} ({d}%)'],'encode' => ['itemName' => 'taskOperate','value' => '2019','tooltip' => '2019']];

        $line[] = $last;

        $return = [
            'source' => $list,
            'line' => $line
        ];
        exit(json_encode([
            'success' => 1,
            'msg' => '获取成功',
            'data' => $return
        ]));
    }

    function ajaxPieData(){
        $this->load->model('MAdminGroup');
        $this->load->model('MTaskRecords');

        $allReviews = $this->MAdminGroup->getReviews();
        ksort($allReviews);
        $data = $this->MTaskRecords->getPieData(array_values($allReviews));
        $total = $this->MTaskRecords->getAllData();

        exit(json_encode([
            'success' => 1,
            'msg' => '获取成功',
            'data' => [
                'group' => array_values($allReviews),
                'data'  => $data,
                'total' => $total
            ]
        ]));
    }

    public function ajaxBlockData()
    {
        $this->load->model('MAdminGroup');
        $this->load->model('MTaskRecords');
        $this->load->model('MTaskApplyNum');
        $this->load->library('FormFilter');
        $this->load->helper('formfilter');
        $data = $this->input->post();

        $begintime = filterValue('task_operate_create_time_begin');
        $endtime = filterValue('task_operate_create_time_end');

        //销售组与测评组
        $allReviews = $this->MAdminGroup->getChooseReviews($data['group_id']);
        $list = $this->MTaskRecords->getStaticData($begintime, $endtime, $data['type'],$allReviews);

        $line = array();
        foreach ($allReviews as $v){
            $line[] = $v;
        }
        $return = [
            'source' => $list,
            'line' => $line,
        ];
        exit(json_encode([
            'success' => 1,
            'msg' => '获取成功',
            'data' => $return
        ]));
    }

    public function ajaxDetail(){
        $this->load->model('MTaskRecords');
        $list = $this->MTaskRecords->getStaffDetail($this->input->post('person'));

        exit(json_encode([
            'success' => 1,
            'msg' => '获取成功',
            'data' => $list
        ]));
    }

}
